<!DOCTYPE html>
<html>
    <head>
        <title>公式编辑器</title>
        <meta charset="UTF-8" />
        <meta name="renderer" content="webkit" />
        <script src="lib/jquery-1.11.0.min.js"></script>
        <script src="lib/kitygraph.all.min.js"></script>
        <script src="lib/kity-formula-render.all.min.js"></script>
        <script src="lib/kity-formula-parser.all.min.js"></script>
        <script src="lib/kityformula-editor.all.min.js"></script>
        <script>
            jQuery(function ($) {
                var factory = kf.EditorFactory.create($('#kfEditorContainer')[0], {
                    render: {
                        fontsize: 40,
                        padding: [0, 0]
                    },
                    resource: {
                        path: 'resource/'
                    }
                });

                factory.ready(function (KFEditor) {
                    // this指向KFEditor

                    this.execCommand('render', '\\placeholder');
                    this.execCommand('focus');

                    window.kfe = this;
                });

                $('.quick-dialog-confirm-btn').on('click', function () {
                    var $textArea = $('#quick-latex-textarea');
                    var latex = $textArea.val();
                    $textArea.val('');
                    $('.quick-dialog').hide();
                    if (latex) {
                        window.kfe.execCommand('render', latex);
                    }
                });

                $('.quick-dialog-cancel-btn').on('click', function () {
                    $('#quick-latex-textarea').val('');
                    $('.quick-dialog').hide();
                });
            });
        </script>
        <link rel="stylesheet" href="assets/styles/page.css" />
        <link rel="stylesheet" href="assets/styles/base.css" />
        <link rel="stylesheet" href="assets/styles/ui.css" />
        <link rel="stylesheet" href="assets/styles/scrollbar.css" />
        <style>
            #kfEditorContainer {
                box-sizing: border-box;
            }

            .quick-dialog {
                position: fixed;
                top: 0;
                left: 0;
                right: 0;
                bottom: 0;
                z-index: 9999;
                display: none;
                /*display: flex;*/
                justify-content: center;
                align-items: center;
                background: rgba(0, 0, 0, 0.3);
            }
            .quick-dialog__wrapper {
                box-sizing: border-box;
                width: 50%;
                padding: 16px 24px;
                background: #ffffff;
            }

            #quick-latex-textarea {
                box-sizing: border-box;
                width: 100%;
                min-height: 100px;
                padding: 8px 12px;
                color: #333333;
                font-size: 14px;
            }

            .quick-dialog__footer {
                text-align: right;
            }

            .quick-dialog-btn {
                cursor: pointer;
                background: #ffffff;
                border: 0;
                font-size: 14px;
                color: #333333;
                margin-left: 12px;
                margin-top: 10px;
            }
        </style>
    </head>
    <body>
        <div id="kfEditorContainer" class="kf-editor" style="width: 100%; height: 500px"></div>
        <div class="quick-dialog">
            <div class="quick-dialog__wrapper">
                <textarea
                    name="latex"
                    id="quick-latex-textarea"
                    cols="30"
                    rows="8"
                    placeholder="请输入latex公式"
                ></textarea>
                <div class="quick-dialog__footer">
                    <button class="quick-dialog-btn quick-dialog-cancel-btn">取消</button>
                    <button class="quick-dialog-btn quick-dialog-confirm-btn">确定</button>
                </div>
            </div>
        </div>
    </body>
</html>
